import { Application } from 'egg';

export default (app: Application) => {
    const { router, controller } = app;
    // 首页根域名 http://127.0.0.1:7001/
    router.get('/', controller.test.index.index);

    // 注意：如果有命名空间，则不能使用 根域名形式 http://127.0.0.1:7001/test/ ，只能使用 http://127.0.0.1:7001/test/list
    const TEST_MODULE = '/test';
    const testRouter = router.namespace(TEST_MODULE + '/index');

    const rateLimitRepeat = app.middleware.rateLimitRepeat();

    testRouter.get('/index', controller.test.index.index);
    testRouter.get('/list', controller.test.index.list);
    testRouter.get('/create', rateLimitRepeat, controller.test.index.create);
    testRouter.get('/update', rateLimitRepeat, controller.test.index.update);
    testRouter.get('/detail', controller.test.index.detail);
    testRouter.get('/delete', controller.test.index.delete);

    testRouter.get('/redis', controller.test.index.redis);

    const crudRouter = router.namespace(TEST_MODULE + '/crud');
    crudRouter.get('/list', controller.test.crud.list);
    crudRouter.get('/create', controller.test.crud.create);
    crudRouter.get('/update', controller.test.crud.update);
    crudRouter.get('/detail', controller.test.crud.detail);
    crudRouter.get('/delete', controller.test.crud.delete);
};